using Net.Messgae;

public class HeartbeatModel
{
    bool _started = false;
    float _timeCount = 0f;
    static readonly float _timeSize = 5f;

    public void Init(NetworkManager networkManager)
    {
        networkManager.SetTcpConnectedEvent(OnConnected,true);
        networkManager.SetTcpDisconnectedEvent(OnDisconnected,true);
    }

    void OnConnected()
    {
        _started = true;
        _timeCount = 0f;
    }

    void OnDisconnected()
    {
        _started = false;
        _timeCount = 0f;
    }

    public void Update(float delta)
    {
        if(!_started)
        {
            return;
        }

        _timeCount += delta;
        if(_timeCount > _timeSize)
        {
            _timeCount = 0f;
            Model.Instance().msgHandler.SendEmptyMessage(MessageId.None);
        }
    }
}